<template>
	<view class="content">
		<view class="content_title">
			投诉描述
		</view>
		<view class="content_box">
			<textarea v-model="content" placeholder="请输入投诉内容"></textarea>
		</view>
		<view class="content_title">
			证据截图（选填）
		</view>
		<view class="content_box">
			<uv-upload :fileList="fileList" multiple :maxCount="1" @afterRead="afterRead"
				@delete="deletePic"></uv-upload>
		</view>
		<view class="content_button" @click="tijiao">提交</view>
	</view>
</template>

<script setup>
	import {
		ref
	} from 'vue'
	import {
		homeApi
	} from "@/api/index"
	import {
		onLoad,
		onShow
	} from '@dcloudio/uni-app'
	import {
		link,uploadFilePromise
	} from '@/utils/utils.js'
	
	const fileList = ref([])
	const imgunikeys = ref('')
	const deletePic = (event) => {
		fileList.value.splice(event.index, 1)
		imgunikeys.value = ''
	}
	const afterRead = async(event) => {
		let lists = [].concat(event.file)
		let fileListLen = fileList.value.length
		lists.map((item) => {
			fileList.value.push({
				...item,
				status: 'uploading',
				message: '上传中'
			})
		})
		for (let i = 0; i < lists.length; i++) {
			const result = await uploadFilePromise(lists[i].url)
			let item = fileList.value[fileListLen]
			imgunikeys.value=result.columns[0].imgunikey
			fileList.value.splice(fileListLen, 1, Object.assign(item, {
				status: 'success',
				message: '',
				url: result.columns[0].imgurl,
			}))
			fileListLen++
		}
	}
	const content = ref('')
	const tijiao = async()=>{
		let data = {
			content:content.value,
			imgunikey:imgunikeys.value
		}
		let res = await homeApi.publicPost(data,'txlfankui')
		for (let i = 0; i < res.columns.length; i++) {
			if (res.columns[i].name == 'txlfankui') {
				if(res.columns[i].statuscode=='200'){
					uni.showToast({
						title: res.columns[0].message,
						icon:'none',
						duration: 2000
					});
					setTimeout(() => {
						uni.navigateBack({
							delta:1
						})
					}, 2000)
				}else{
					uni.showToast({
						title: res.columns[0].message,
						icon:'none',
						duration: 2000
					});
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content{
		width: 100%;
		&_title{
			width: calc(100% - 60rpx);
			padding: 30rpx;
			font-size: 32rpx;
			background: #f5f6fa;
		}
		&_box{
			width: calc(100% - 60rpx);
			padding: 30rpx;
			background: #fff;
			textarea{
				font-size: 28rpx;
				width: 100%;
				height: 250rpx;
			}
		}
		&_button{
			width: calc(100% - 60rpx);
			margin: 0 auto;
			margin-top: 50rpx;
			height: 100rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			color: #fff;
			background: linear-gradient(120deg, #f31801, #e94f06);
			border-radius: 8px;
		}
	}
</style>